#include <cstdio>
struct nod{
	char name[6];
	int year;
	int month;
	int day;
}tmp,youthest,oldest,left,right;
bool greater(nod left,nod right)
{
	if(left.year!=right.year)return left.year>right.year;
	else if(left.month!=right.month)return left.month>right.month;
	else return left.day>right.day;
}
int init()
{
	youthest.year=left.year=1814;
	youthest.month=left.month=9;
	youthest.day=left.day=5;    
	oldest.year=right.year=2014;
	oldest.month=right.month=9;
	oldest.day=right.day=7;
}
int main()
{
	int num;
	scanf("%d",&num);
	int count=0;
	init();
	while(num--)
	{
		scanf("%s %d/%d/%d",tmp.name,&tmp.year,&tmp.month,&tmp.day);
		//scanf("%s %d",tmp.name,&tmp.year);
		//getchar();
		//scanf("%d",&tmp.month);
		//getchar();
		//scanf("%d",&tmp.day);
		if(greater(tmp,left)&&greater(right,tmp))
		{
			++count;
			if(greater(oldest,tmp))
			{
				oldest=tmp;
			}
			if(greater(tmp,youthest))
			{
				youthest=tmp;
			}
		}
	}
	if(0==count)printf("0\n");//这里必须对没有合法输入的情况进行判断，防止输出多余的空格
	else printf("%d %s %s\n",count,oldest.name,youthest.name);
	return 0;
}
